const App = getApp();

// 富文本插件
import wxParse from '../../../../wxParse/wxParse.js';
// pages/nav/project/projectDetail/index.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        active: 0,
        content:"",
        projectDetail:{},
        detailId:'',
        investment_demand:'',
        supporting_settings:'',
        indicatorDots: true, // 是否显示面板指示点
    autoplay: true, // 是否自动切换
    interval: 3000, // 自动切换时间间隔
    duration: 800, // 滑动动画时长

    currentIndex: 1, // 轮播图指针
    },
    previewImage(e){
        console.log(e,'eee');
        wx.previewImage({
            current: e.currentTarget.dataset.image, // Current image URL
            urls: [e.currentTarget.dataset.image] // List of all image URLs
          });
    },
    onPreviewImages(e) {
        let _this = this;
        let index = e.currentTarget.dataset.index,
          imageUrls = [];
        _this.data.projectDetail.swiper_images.forEach(item => {
          imageUrls.push(item.file_path);
        });
        wx.previewImage({
          current: imageUrls[index],
          urls: imageUrls
        })
      },
      setCurrent(e) {
        let _this = this;
        _this.setData({
          currentIndex: e.detail.current + 1
        });
      },
    getProjectDetail() {
        let _this = this;
        App._post_form('project/detail', {
            project_id: _this.data.detailId,
        }, function(result) {
            if (_this.data.active == 0) {
                wxParse.wxParse('content', 'html', result.data.detail.content, _this, 0);
            } else if (_this.data.active == 1) {
                
                wxParse.wxParse('content', 'html', result.data.detail.supporting_settings, _this, 0);

            } else if (_this.data.active == 2) {
                wxParse.wxParse('content', 'html', result.data.detail.investment_demand, _this, 0);
                // wxParse.wxParse('content', 'html', result.data.detail.supporting_settings, _this, 0);
            }
            
           
           
          
            _this.setData({
                projectDetail:result.data.detail,
            })
          });
    },
    onChange(event) {
        console.log(event,'event');
        this.setData({
            active:event.detail.index
        })
        this.getProjectDetail()
      },
      goJoin(){
       wx.navigateTo({
         url: '/pages/join/index?id=' + this.data.detailId,
       })
      },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
       
        this.setData({
            detailId:options.id
        })
        this.getProjectDetail()
        
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})